<template>
  <a-select
    style="width:100%"
    v-bind="instance"
    v-model="defaultValue"
    @change="handleChange">
    <a-select-option v-for="item in instance.list" :value="item.value" :key="item.value">
      {{item.label}}
    </a-select-option>
  </a-select>
</template>

<script>
export default {
  props: {
    // 数据类型是object
    instance: Object
  },
  data() {
    return {
      defaultValue: undefined,
      selectOpt: {} // 配置
    }
  },
  watch: {
    instance: {
      handler(nVal) {
        Object.assign(this, { ...nVal }) // 把传入的参数，融合到this中
      },
      deep: true,
      immediate: true
    }
  },
  created() {
    this.handlerCustomList() // 处理有可能通过url获取list的情况
  },
  methods: {
    handlerCustomList() {
      const { isCustomList, customRequestList } = this.instance
      if (customRequestList && isCustomList) {
        customRequestList.call(this, this.instance)
      }
    },
    update(list) {
      this.$set(this.instance, 'list', list)
    },
    handleChange(value) {
      this.$emit('change', value)
    }
  }
}
</script>
